package com.ryder.ryderschool.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ryder.ryderschool.common.Result;
import com.ryder.ryderschool.entity.ProjectResult;
import com.ryder.ryderschool.service.ProjectResultService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/projects/{projectId}/results")
@RequiredArgsConstructor
public class ProjectResultController {

    private final ProjectResultService projectResultService;

    @PostMapping
    public Result<Void> createResult(
            @PathVariable Integer projectId,
            @RequestBody ProjectResult result) {
        result.setProjectId(projectId);
        projectResultService.createResult(result);
        return Result.success();
    }

    @PutMapping("/{id}")
    public Result<Void> updateResult(
            @PathVariable Integer projectId,
            @PathVariable Integer id,
            @RequestBody ProjectResult result) {
        result.setId(id);
        result.setProjectId(projectId);
        projectResultService.updateResult(result);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteResult(
            @PathVariable Integer projectId,
            @PathVariable Integer id) {
        projectResultService.deleteResult(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<ProjectResult> getResult(
            @PathVariable Integer projectId,
            @PathVariable Integer id) {
        return Result.success(projectResultService.getResult(id));
    }

    @GetMapping
    public Result<Page<ProjectResult>> listResults(
            @PathVariable Integer projectId,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.success(projectResultService.listResults(projectId, pageNum, pageSize));
    }
} 